﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserOptionManager.aspx.cs"
    Inherits="ZLDC.Estate.TM.UserOptionManager" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>查询显示配置</title>
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    
</head>
<body>
    <div class="f_l rqieh" id="div_tab">
        <a class="y" style="cursor: pointer;" onclick="go_to(1);">盘源</a> <a style="cursor: pointer;"
            onclick="go_to(2);">客源</a> <a style="cursor: pointer;" onclick="go_to(3);">楼盘字典</a>
    </div>
    <div id="divList" class="page f_l">
        <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
            <tr>
                <td width="50%" align="center" bgcolor="#F7F7F7" colspan="5">
                    <strong>隐藏列</strong> <strong style="margin-left: 25%;">显示列</strong>
                </td>
            </tr>
            <tr>
                <td width="100%" align="center" bgcolor="#F7F7F7">
                    <table>
                        <tr>
                            <td>
                                <select size="40" id="sParamHide" name="sParamHide" style="width: 220px; z-index:1;" language="javascript">
                                </select>
                            </td>
                            <td>
                                &nbsp;&nbsp;
                                <input id="btnAdd" type="button" value="添加 ->" onclick="return  LexunJS.ListBoxAddOne('sParamHide', 'sParamShow')" />&nbsp;&nbsp;
                                <br />
                                <br />
                                &nbsp;&nbsp;
                                <input id="btnAddAll" type="button" value="全加 >>" onclick="return  LexunJS.ListBoxAddAll('sParamHide', 'sParamShow')" />&nbsp;&nbsp;
                                <br />
                                <br />
                                <br />
                                &nbsp;&nbsp;
                                <input id="btnLess" type="button" value="<- 移出" onclick="return LexunJS.ListBoxAddOne('sParamShow', 'sParamHide')" />&nbsp;&nbsp;
                                <br />
                                <br />
                                &nbsp;&nbsp;
                                <input id="btnLessAll" type="button" value="<< 全移" onclick="return LexunJS.ListBoxAddAll('sParamShow', 'sParamHide')" />&nbsp;&nbsp;
                                <br />
                                <br />
                            </td>
                            <td>
                                <select size="40" id="sParamShow" name="sParamShow" style="width: 220px;" language="javascript">
                                </select>
                            </td>
                            <td>
                                &nbsp;<input id="btnUp" type="button" value="上移" onclick="return LexunJS.ListBoxUp('sParamShow')" /><br />
                                <br />
                                &nbsp;<input id="btnDown" type="button" value="下移" onclick="return LexunJS.ListBoxDown('sParamShow')" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    <div style="padding-top: 15px; cursor: pointer; text-align: center;">        
        <input id="btnOk" class="button_bak" type="button" value="确定" onclick="submitOK()" /> 
    </div>
    <input id="hTypeID" name="hTypeID" value="1" type="hidden" />

    <script src="../js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script src="../js/LexunJS.js" type="text/javascript"></script>

    <script type="text/javascript" language="javascript">

        $(document).ready(function() {
            showShowList(1);       // 查询显示列
            showHideList(1);       // 查询隐藏列 1.盘源列表 2.客源列表 3.楼盘字典列表
        });

        // 查询显示列
        function showShowList(typeid) {
            $("#sParamShow").html("");
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerSystem.ashx',
                data: 'act=useroption_detail&typeid=' + typeid,
                timeout: '10000',
                error: function() {
                    alert("修改失败！");
                },
                success: function(json) {
                    showShowListCallBack(json);
                }
            });
        }

        function showShowListCallBack(response) {
            var json = eval("(" + response + ")");

            // 动态表头、动态列
            var fieldnames = json.field.fieldnames;
            var fieldvalues = json.field.fieldvalues;

            var fieldnameArray = new Array();
            var fieldvalueArray = new Array();

            fieldnameArray = fieldnames.split(",");
            fieldvalueArray = fieldvalues.split(",");

            var obj = document.getElementById("sParamShow");

            for (i = 0; i < fieldnameArray.length; i++) {
                LexunJS.ListBoxAdd(obj, fieldvalueArray[i], fieldnameArray[i]);
            }
        }

        // 查询隐藏列
        function showHideList(typeid) {            
            $("#sParamHide").html("");
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerSystem.ashx',
                data: 'act=useroption_hide&typeid=' + typeid,
                timeout: '10000',
                error: function() {
                    alert("修改失败！");
                },
                success: function(json) {
                    showHideListCallBack(json);
                }
            });
        }

        function showHideListCallBack(response) {                
            var json = eval("(" + response + ")");
            var record = json.record;

            if (record != null && record.length > 0) {
                var obj = document.getElementById("sParamHide");

                var recordLength = record.length;
                for (var i = 0; i < recordLength; i++) {
                    LexunJS.ListBoxAdd(obj, record[i].mark3, record[i].item);
                }
            }
        }

        // 跳转 num(跳到第几个标签)
        function go_to(num) {
            var tabs = document.getElementById("div_tab").getElementsByTagName("a");

            for (var i = 1; i <= tabs.length; i++) {
                if (num == i) {
                    tabs[i - 1].className = "y";
                } else {
                    tabs[i - 1].className = "";
                }
            }

            $("#hTypeID").val(num);

            $("#sParamShow").html("");
            $("#sParamHide").html("");

            showShowList(num);
            showHideList(num);
        }

        // 提交前验证
        function submitOK() {
            var typeid = $("#hTypeID").val();       // 1.盘源列表 2.客源列表 3.楼盘字典列表 
            var obj = document.getElementById("sParamShow");        
            var objLength = obj.length;

            if (objLength <= 0) {
                alert("至少选择一个显示列！");
                return false;
            }

            if (objLength > 15) {
                alert("最多只能允许15个显示列,否则影响列表显示效果！");
                return false;
            }            

            var fieldname = "";
            var fields = "";
            var mark1 = "a.id,";    // 始终出现的列
            if (typeid == 1)
                mark1 += "a.haskey,a.isonly,a.hasphoto,a.status,a.status1,a.isvalid,a.recommend,a.ctycont,a.protected,a.tradetype"; 
            else if (typeid == 2)
                mark1 += "a.status,a.dltflag,a.isvalid,a.isself,";
            else if (typeid == 3)
                mark1 += "a.delflag,a.isvalid,";          
                
            for (var i = 0; i < objLength; i++) {
                var selText = obj.options[i].text;
                var selValue = obj.options[i].value;
                if (selText == "")
                    continue;

                fieldname += selText;
                fields += selValue;
                mark1 += "a.[" + selValue + "] as field" + (i + 1);

                if (i < objLength - 1) {
                    fieldname += ",";
                    fields += ",";
                    mark1 += ",";
                }
            }
           
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerSystem.ashx',
                data: 'act=useroption_save&typeid=' + typeid + '&fieldname=' + escape(fieldname) + '&fields=' + escape(fields) + '&mark1=' + escape(mark1),
                timeout: '10000',
                error: function() {
                    alert("修改失败！");
                },
                success: function(json) {
                    alert(json);
                    showShowList(typeid);
                    showHideList(typeid);
                }
            });            
           
        }


    </script>

</body>
</html>
